<?php

namespace plugin\admin\app\controller;

use support\Request;
use support\Response;
use plugin\admin\app\model\RlAssemblyLocation;
use plugin\admin\app\controller\Crud;
use support\exception\BusinessException;

/**
 * 集合地点 
 */
class RlAssemblyLocationController extends Crud
{
    
    /**
     * @var RlAssemblyLocation
     */
    protected $model = null;

    /**
     * 构造函数
     * @return void
     */
    public function __construct()
    {
        $this->model = new RlAssemblyLocation;
    }
    
    /**
     * 浏览
     * @return Response
     */
    public function index(): Response
    {
        return view('rl-assembly-location/index');
    }

    /**
     * 插入
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function insert(Request $request): Response
    {
        if ($request->method() === 'POST') {
            $insert=[
                'location_name'=>$request->post('location_name',''),
                'location_province'=>$request->post('location_province',''),
                'location_city'=>$request->post('location_city',''),
                'location_area'=>$request->post('location_area',''),
                'location_address'=>$request->post('location_address',''),
                'contacts_name'=>$request->post('contacts_name',''),
                'contacts_mobile'=>$request->post('contacts_mobile',''),
                'create_time'=>time()
            ];
            $ret=  $this->model->insert($insert);
            if (!$ret){
                return $this->json(-1);
            }
            return $this->json(0);
        }
        return view('rl-assembly-location/insert');
    }

    /**
     * 更新
     * @param Request $request
     * @return Response
     * @throws BusinessException
    */
    public function update(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return parent::update($request);
        }
        return view('rl-assembly-location/update');
    }

}
